<!-- 基础配置-原材料-新增or修改原材料名称/编号 -->
<template>
  <div id="registerModal">
    <el-dialog :title="title" :visible.sync="open" width="60%" append-to-body :close-on-click-modal="false"
      v-dialogDrag>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-tabs v-model="activeName" class="detail-tab" type="card">
          <el-tab-pane label="基本信息" name="first">
            <el-row :gutter="20">
              <!-- <el-col :span="12">
              <el-form-item label="物资种类" prop="type">
                <el-select style="width: 100%;" placeholder="请选择物资种类" v-model="form.type">
                  <el-option :key="dict.value" :label="dict.label" :value="dict.value"
                    v-for="dict in typeOptions"></el-option>
                </el-select>
              </el-form-item>
            </el-col> -->
              <el-col :span="12">
                <el-form-item label="原材料编号" prop="num">
                  <el-input v-model="form.num" placeholder="请输入原材料编号" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="原材料名称" prop="name">
                  <el-input v-model="form.name" placeholder="请输入原材料名称" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="原材料类型" prop="type">
                  <el-select style="width: 100%;" placeholder="请选择原材料类型" v-model="form.type">
                    <el-option :label="item" :value="item" v-for="(item,index) in typeList" :key="index"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="原材料批次号" prop="batchNum">
                  <el-input v-model="form.batchNum" placeholder="请输入原材料批次号" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="品牌" prop="brand">
                  <el-input v-model="form.brand" placeholder="请输入品牌" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="计量单位" prop="unit">
                  <el-input v-model="form.unit" placeholder="请输入计量单位" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="制造商" prop="manufacturer">
                  <el-input v-model="form.manufacturer" placeholder="请输入制造商" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="产地" prop="origin">
                  <el-input v-model="form.origin" placeholder="请输入产地" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="生产日期" prop="putStorageTime">
                  <el-date-picker style="width: 100%;" clearable placeholder="请选择生产日期" type="date"
                    v-model="form.putStorageTime" value-format="yyyy-MM-dd">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="电压等级" prop="voltageLevel">
                  <el-input v-model="form.voltageLevel" placeholder="请输入电压等级" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="规格型号" prop="speModels">
                  <el-input v-model="form.speModels" placeholder="请输入型号规格" />
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="备注" prop="eipMatDes">
                  <el-input v-model="form.eipMatDes" type="textarea" placeholder="请输入备注" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-tab-pane>
        </el-tabs>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        // 遮罩层
        loading: true,
        activeName: "first",
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 表单参数
        form: {},
        // 表单校验
        rules: {},
        url: {
          getById: '/goodsFundBack/goodsFundBack/',
          add: '/goodsFundBack/goodsFundBack/add',
          edit: '/goodsFundBack/goodsFundBack/edit',
        },
        typeList: ['金属杆', '屏蔽料', '绝缘料', '护套料', '外护套', '铝（铝合金）杆', '镀锌钢线', '铝包钢线', '光纤', '铝包钢', '铝合金线', '硬铝线', '纤膏',
          'PE护套料', '半导电硅胶', '绝缘硅胶', '电磁线', '漆包线', '支撑绝缘体', '铁芯（电压）', '扩张套管', '铜外壳', '套管'
        ],
      }
    },
    methods: {
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          num: null,
          name: null,
          type: null,
          batchNum: null,
          brand: null,
          unit: null,
          manufacturer: null,
          origin: null,
          putStorageTime: null,
          voltageLevel: null,
          speModels: null,
          eipMatDes: null
        };
        this.resetForm("form");
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加原材料编号/名称";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids;
        this.form = row
        this.open = true;
        this.title = "修改原材料编号/名称";
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.$emit('ok');
            } else {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.$emit('ok');
            }
          }
        });
      },
    }
  }
</script>

<style>
</style>
